﻿@model MasResourceItem

@{
    int resSubGrpId = ViewBag.resSubGrpId;
    var resSubGrp = new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient().SelectResourceSubGroup(new MasResourceSubGroup{ResSubGrpId = resSubGrpId}, new []{"MasResourceGroup"}).FirstOrDefault();
    var resGrp = new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient().SelectResourceGroup(new MasResourceGroup{ResGrpId = resSubGrp.ResGrpId.Value},null).FirstOrDefault();
    var resType = new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient().SelectResourceType(new MasResourceType{ResTypeId = resSubGrp.MasResourceGroup.ResTypeId.Value}, null).FirstOrDefault();
    var resItemId = Model != null ? Model.ResItemId : 0;
    ViewBag.CustomMenu = new Dictionary<string, string>
        {
            {
               "ประเภท" + resType.Name , Url.Action("Index", "MasResourceType")
            }, 
            {
                "หมวด" + resGrp.Name , Url.Action("Index", "MasResourceGroup", new {resTypeId=resGrp.ResTypeId})
            }, 
            {
                "กลุ่ม" + resSubGrp.Name , Url.Action("Index", "MasResourceSubGroup", new {resGrpId = resSubGrp.ResGrpId})
            }, 
            {
                "รายการพัสดุ", Url.Action("Index", "MasResourceItem", new {resSubGrpId = resSubGrp.ResSubGrpId})
            }
        };
    ViewBag.resSubGrp = resSubGrp;
    ViewBag.Title = "สร้างรายการพัสดุ";
    ViewBag.Descr = "เพิ่มข้อมูลรายการพัสดุ";
}

@using (Html.BeginForm("Create", "MasResourceItem", FormMethod.Post, 
    new { enctype = "multipart/form-data", @class = "form-horizontal", ViewBag.resSubGrpId }))
{
     @Html.AntiForgeryToken() 

    <div class="block-button-menu-above">
        @Html.ButtonViewAll(new {ViewBag.resSubGrpId})
        @Html.ButtonSubmit()
    </div>
    
    @Html.Partial("_EditorForm")
    @Html.ValidationSummary(true, ValidateText.RequiredField, new { @class = "alert alert-error" })

}

@section scripts
{
    <script>
        $(function() {

            $('#MaxQty').ace_spinner({ value: 0, min: 0, max: 1000000000, step: 1, btn_up_class: 'btn-info', btn_down_class: 'btn-info' });
            $('#MinQty').ace_spinner({ value: 0, min: 0, max: 1000000000, step: 1, btn_up_class: 'btn-info', btn_down_class: 'btn-info' });
            $('#StdPrice').ace_spinner({ value: 0, min: 0, max: 1000000000, step: 1, btn_up_class: 'btn-info', btn_down_class: 'btn-info' });
            $('#MinPrice').ace_spinner({ value: 0, min: 0, max: 1000000000, step: 1, btn_up_class: 'btn-info', btn_down_class: 'btn-info' });
            $('#MaxPrice').ace_spinner({ value: 0, min: 0, max: 1000000000, step: 1, btn_up_class: 'btn-info', btn_down_class: 'btn-info' });
            
            

        });
        
        $("form").not("#formsearch").submit(function (e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm("ท่านต้องการยืนยัน ใช่หรือไม่", function (result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });
    </script>
}